package getImg

import (
	"net/http"

	"server-go/api/reward/internal/logic/getImg"
	"server-go/api/reward/internal/svc"
	"server-go/api/reward/internal/types"

	"github.com/zeromicro/go-zero/rest/httpx"
)

func HeadImgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	// 给前端返回图片
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.HeadImgInput
		if err := httpx.Parse(r, &req); err != nil {
			httpx.Error(w, err)
			return
		}

		l := getImg.NewHeadImgLogic(r.Context(), svcCtx)
		resp, err := l.HeadImg(&req)
		w.Header().Set("Content-Type", "image/jpeg")
		if err != nil {
			w.Write([]byte(resp.Data))
		} else {
			w.Write([]byte(resp.Data))
		}
	}
}
